//
//  BBUIButtonViewModel.m
//  BBKit
//
//  Created by apple on 2019/6/28.
//  Copyright © 2019年 baobao. All rights reserved.
//

#import "BBUIButtonViewModel.h"
#import "UIControl+Event.h"

#define BBKIT_SETPRAGRA_UIBUTTON_API(methodName, paraType)    BBKIT_SETPRAGRA_API(methodName,paraType, UIButton, BBUIButtonViewModel*)

//setAttributedTitle
#define BBKIT_SETBUTTON_NSATTRIBUTEDTITLE_API(methodName,State) BBKIT_SETBUTTON_API(methodName,NSAttributedString *,setAttributedTitle,State)

//setBackgroundColor
#define BBKIT_SETBUTTON_BACKGROUNDCOLOR_API(methodName,State)   BBKIT_SETBUTTON_API(methodName,UIColor *,setBackgroundColor,State)

//setBackgroundImage
#define BBKIT_SETBUTTON_BACKGROUNDIMAGE_API(methodName,State) BBKIT_SETBUTTON_API(methodName,UIImage *,setBackgroundImage,State)

//setImage
#define BBKIT_SETBUTTON_IMAGE_API(methodName,State) BBKIT_SETBUTTON_API(methodName,UIImage *,setImage,State)

//设置setTitleShadowColor
#define BBKIT_SETBUTTON_TITLESHADOWColor_API(methodName,State) BBKIT_SETBUTTON_API(methodName,UIColor *,setTitleShadowColor,State)

//设置setTitleColor
#define BBKIT_SETBUTTON_TITLEColor_API(methodName,State) BBKIT_SETBUTTON_API(methodName,UIColor *,setTitleColor,State)

//setTitle
#define BBKIT_SETBUTTON_TITLE_API(methodName,State)    BBKIT_SETBUTTON_API(methodName,NSString *,setTitle,State)

#define BBKIT_SETBUTTON_API(methodName,ParamType,ButtonCode,State)\
- (BBUIButtonViewModel * (^)(ParamType param))methodName{\
return ^(ParamType param){\
    [(UIButton *)self.view ButtonCode:param forState:State];\
    return self;\
};\
}


@implementation BBUIButtonViewModel

//- (BBUIButtonViewModel * (^)(NSString *title))title{
//    return ^(NSString *title){
//      [(UIButton *)self.view setTitle:title forState:UIControlStateNormal];
//        return self;
//    };
//}

//设置title
BBKIT_SETBUTTON_TITLE_API(title, UIControlStateNormal);
BBKIT_SETBUTTON_TITLE_API(titleHL, UIControlStateHighlighted);
BBKIT_SETBUTTON_TITLE_API(titleSelected, UIControlStateSelected);
BBKIT_SETBUTTON_TITLE_API(titleDisabled, UIControlStateDisabled);

//设置TitleColor
BBKIT_SETBUTTON_TITLEColor_API(titleColor, UIControlStateNormal);
BBKIT_SETBUTTON_TITLEColor_API(titleColorHL, UIControlStateHighlighted);
BBKIT_SETBUTTON_TITLEColor_API(titleColorSelected, UIControlStateSelected);
BBKIT_SETBUTTON_TITLEColor_API(titleColorDisabled, UIControlStateDisabled);

//设置TitleShadowColor
BBKIT_SETBUTTON_TITLESHADOWColor_API(titleShadowColor, UIControlStateNormal);
BBKIT_SETBUTTON_TITLESHADOWColor_API(titleShadowColorHL, UIControlStateHighlighted);
BBKIT_SETBUTTON_TITLESHADOWColor_API(titleShadowColorSelected, UIControlStateSelected);
BBKIT_SETBUTTON_TITLESHADOWColor_API(titleShadowColorDisabled, UIControlStateDisabled);

//设置Image
BBKIT_SETBUTTON_IMAGE_API(image, UIControlStateNormal);
BBKIT_SETBUTTON_IMAGE_API(imageHL, UIControlStateHighlighted);
BBKIT_SETBUTTON_IMAGE_API(imageSelected, UIControlStateSelected);
BBKIT_SETBUTTON_IMAGE_API(imageDisabled, UIControlStateDisabled);

//设置BackgroundImage
BBKIT_SETBUTTON_BACKGROUNDIMAGE_API(backgroundImage, UIControlStateNormal);
BBKIT_SETBUTTON_BACKGROUNDIMAGE_API(backgroundImageHL, UIControlStateHighlighted);
BBKIT_SETBUTTON_BACKGROUNDIMAGE_API(backgroundImageSelected, UIControlStateSelected);
BBKIT_SETBUTTON_BACKGROUNDIMAGE_API(backgroundImageDisabled, UIControlStateDisabled);

//设置BackgroundColor
//BBKIT_SETBUTTON_BACKGROUNDCOLOR_API(backgroundColorHL, UIControlStateHighlighted);
//BBKIT_SETBUTTON_BACKGROUNDCOLOR_API(backgroundColorSelected, UIControlStateSelected);
//BBKIT_SETBUTTON_BACKGROUNDCOLOR_API(backgroundColorDisabled, UIControlStateDisabled);
- (BBUIButtonViewModel * (^)(UIColor *backgroundColor))backgroundColor{
    return ^(UIColor *backgroundColor){
        [(UIButton *)self.view setBackgroundColor:backgroundColor];
        return self;
    };
}


//设置AttributedTitle
BBKIT_SETBUTTON_NSATTRIBUTEDTITLE_API(attributedTitle, UIControlStateNormal);
BBKIT_SETBUTTON_NSATTRIBUTEDTITLE_API(attributedTitleHL, UIControlStateHighlighted);
BBKIT_SETBUTTON_NSATTRIBUTEDTITLE_API(attributedTitleSelected, UIControlStateSelected);
BBKIT_SETBUTTON_NSATTRIBUTEDTITLE_API(attributedTitleDisabled, UIControlStateDisabled);

- (BBUIButtonViewModel *(^)(UIFont *titleFont))titleFont
{
    return ^BBUIButtonViewModel *(UIFont *titleFont) {
        ((UIButton *)self.view).titleLabel.font = titleFont;
        return self;
    };
}

BBKIT_SETPRAGRA_UIBUTTON_API(contentEdgeInsets, UIEdgeInsets);
BBKIT_SETPRAGRA_UIBUTTON_API(titleEdgeInsets, UIEdgeInsets);
BBKIT_SETPRAGRA_UIBUTTON_API(imageEdgeInsets, UIEdgeInsets);


#pragma mark - # UIControl
BBKIT_SETPRAGRA_UIBUTTON_API(enabled, BOOL);
BBKIT_SETPRAGRA_UIBUTTON_API(selected, BOOL);
BBKIT_SETPRAGRA_UIBUTTON_API(highlighted, BOOL);

- (BBUIButtonViewModel *(^)(UIControlEvents controlEvents, void (^eventBlock)(id sender)))eventBlock
{
    
    return ^BBUIButtonViewModel *(UIControlEvents controlEvents, void (^eventBlock)(id sender)) {
        [(UIControl *)self.view addControlEvents:controlEvents handler:eventBlock];
        return self;
    };
}

BBKIT_SETPRAGRA_UIBUTTON_API(contentVerticalAlignment, UIControlContentVerticalAlignment);
BBKIT_SETPRAGRA_UIBUTTON_API(contentHorizontalAlignment, UIControlContentHorizontalAlignment);
@end
